<?
#####################################################
#  COPYRIGHT NOTICE
#####################################################
# In the following statements, the term "this 
# program" refers to all files associated with the
# execution and distribution of Adtrackz.
#
# This Program is Copyright 2004 Jonah Klimack.
# All Rights Reserved. 
#
# Selling the code for this program, modifying 
# and/or redistributing the code for this program
# in part or in whole over the Internet or in any 
# other medium is expressly forbidden. Violators
# will be prosecuted to the fullest extent of the law
# Copyright and header information may not be
# modified.
#
# This program is distributed "as is" and without 
# warranty of any kind, either express or implied.
# In no event shall the liability of Jonah Klimack 
# for any damages, losses and/or causes of 
# action exceed the total amount paid by the 
# user for this software.		
#####################################################
# DO NOT MODIFY ANYTHING IN THIS FILE
#####################################################



require "header.php";
require "submenu.php";

$label = mysql_fetch_row(mysql_query("select adcode from adtrackz_campaigns where ID='$cID'"));

//make sure this is under a campaign
if (!$cID)
	alert("you must create a new subcampaign under an existing campaign; there is no campaign selected");
else
{
	$campaigndata = mysql_fetch_row(mysql_query("select * from adtrackz_campaigns where ID='$cID'"));
?>

<table width="100%">
<tr>
	<td>
		<p class="small" align="left">Campaigns > <?=$label[0]?> > Edit</p>
	</td>
	<td>
		<? load_submenu($cID,$label[0]) ?>
	</td>
</tr>
</table>

<p class="heading">
Add A SubCampaign To <?=$campaigndata[2]?>
</p>
<p>
Add a new subcampaign to the existing campaign by filling out this form.
</p>
<br>

<?
if ($submit) //ADD SUBCAMPAIGN
{
	//check data
	$duplicate = mysql_fetch_row(mysql_query("select adcode from adtrackz_subcampaigns where campaignID='$cID' && adcode='$adcode'"));
	if ($duplicate[0])
		error("The subcampaign has already been created, please choose another adcode");	
	elseif (strlen($adcode) > 100)
		error("adcode must be less than 100 characters.");
	elseif (!$adcode)
		error("ad code is a required field.");
	//disabled to allow [ " - chacters (matching broad keywords in google)
	//elseif (preg_match("/(\W+|\s+)/", $adcode, $matches))
	//	error("Ad code must contain letters,digits or and underscore character only.");
	elseif (strlen($url) > 255)
		error("Url must be less than 255 characters.");
	elseif (!$url)
		error("Url is a required field.");
	elseif (!preg_match("/http:\/\//", $url))
		error("Url is not valid.");
	elseif (!preg_match("/\b\d+\b/", $cost))
		error("Cost must be in numerical format.");
	else
	{
		//search for this sub


		if ($ppc)
			$ppc = 1;
		
		$adcode = trim($adcode);
		$adcode = strtolower($adcode);		
		//strip & and | characters
		$adcode = str_replace("&","",$adcode);
		$adcode = str_replace("|","",$adcode);

		mysql_query("insert into adtrackz_subcampaigns values ('','$cID','$adcode', '$url', '$cost', '$description', '$ppc')");

		$adcode = stripslashes($adcode);

		alert ("$adcode has been successfully added to $campaigndata[2].");
	}
}

//set variables that can't be edited
$group = $campaigndata[1];
$purpose = $campaigndata[8];
$startdatest = strtotime($campaigndata[5]);
$startdate = date("D M j, Y", $startdatest);
$enddatest = strtotime($campaigndata[6]);
$enddate = date("D M j, Y", $enddatest);

?>

<br>
<form action="addsub.php" method="post">
<table width="500" border="0" cellspacing="0" cellpadding="5" align="center" bgcolor="white"  bordercolor="white">
<tr>
	<td valign="top">Ad Code</td>
	<td valign="top">
		<input type="text" size="20" name="adcode" value=""> 		
	</td>
</tr>
<tr>
	<td valign="top">Url</td>
	<td valign="top">
		<input type="text" size="30"  name="url" value="http://">
	</td>
</tr> 
<tr>
	<td>Group:
	<td>
		<?

		//group
		if (!$campaigndata[1])
			echo "default";
		else
		{
			$groupdata = mysql_fetch_row(mysql_query("select groupname from adtrackz_groups where ID='$campaigndata[1]'"));
			echo $groupdata[0];
		}
		?>
	</td>
</tr>
<tr>
	<td>Purpose:
	<td>
		<?
		if ($purpose == "all")
			echo "Clicks, Actions & Sales";
		elseif ($purpose == "clicks")
			echo "Clicks Only";
		elseif ($purpose == "actions")
			echo "Clicks & Actions";
		elseif ($purpose == "sales")
			echo "Clicks & Sales";
		elseif ($purpose == "affiliate")
			echo "Clicks, Sales, Actions on Affiliate Websites";
		?>
	</td>
</tr>
<tr>
	<td valign="top">Cost</td>
	<td valign="top">
		<input type="text" size="6" maxlength="10" name="cost" value="0.00"> 
	</td>
</tr>
<tr>
	<td valign="top">Cost Type</td>
	<td valign="top">
		<input type="checkbox" name="ppc">PPC<br>
	</td>
</tr> 
<tr>
	<td valign="top">Start Date</td>
	<td valign="top">
		<?=$startdate?>
	</td>
</tr>
<tr>
	<td valign="top">End Date</td>
	<td valign="top">
		<?=$enddate?>
	</td>
</tr>
<tr>
	<td valign="top">Description</td>
	<td valign="top">
		<textarea rows="3" cols="20" name="description"></textarea>
	</td>
</tr>
</table>

<br><br>
<center>
<input type="hidden" name="cID" value="<?=$cID?>">
<input type="hidden" name="sID" value="<?=$sID?>">
<input type="submit" name="submit" value="Add SubCampaign"  >
</center></form><br>


<?
}
require "footer.php";

?>